package pers.cloud.cos.qiniu.config;


import com.qiniu.common.Zone;
import pers.cloud.cos.throwable.MyCloudCOSException;

public class QiniuCOSConfig {

    public QiniuCOSConfig(){}

    public QiniuCOSConfig(QiniuCOSConfig qiniuCOSConfig){
        this.accessKey = qiniuCOSConfig.accessKey;
        this.secretKey = qiniuCOSConfig.secretKey;
        this.bucketName = qiniuCOSConfig.bucketName;
    }

    private String accessKey;

    private String secretKey;

    private String bucketName;

    private Zone zone;

    public String getAccessKey() {
        return accessKey;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public String getBucketName() {
        return bucketName;
    }

    public Zone getZone() {
        return zone;
    }

    public static class Builder{
        private QiniuCOSConfig qiniuCOSConfig;

        public Builder(){
            qiniuCOSConfig = new QiniuCOSConfig();
        }

        public Builder addAccessKey(String accessKey){
            qiniuCOSConfig.accessKey = accessKey;
            return this;
        }

        public Builder addSecretKey(String secretKey){
            qiniuCOSConfig.secretKey = secretKey;
            return this;
        }

        public Builder addBucketName(String bucketName){
            qiniuCOSConfig.bucketName = bucketName;
            return this;
        }

        public Builder addZone(Zone zone){
            qiniuCOSConfig.zone = zone;
            return this;
        }
        /**
         * 构建七牛云COS配置
         * @return 七牛云COS配置
         * @throws MyCloudCOSException
         */
        public QiniuCOSConfig build() throws MyCloudCOSException {
            if(qiniuCOSConfig.bucketName == null){
                throw new MyCloudCOSException("空间名不能为空！");
            }
            if(qiniuCOSConfig.secretKey == null){
                throw new MyCloudCOSException("secretKey不能为空！");
            }
            if(qiniuCOSConfig.accessKey == null){
                throw new MyCloudCOSException("accessKey不能为空！");
            }
            if(qiniuCOSConfig.zone == null){
                throw new MyCloudCOSException("地区不能为空！");
            }
            return new QiniuCOSConfig(qiniuCOSConfig);
        }
    }



}
